Skip to content

Accept live thread TIDs in priority syscalls#232

Merged
jserv merged 1 commit into
sysprog21:mainfrom
open-sources-port:getpriority-PRIO_PROCESS
Jul 21, 2026
Merged

Accept live thread TIDs in priority syscalls#232
jserv merged 1 commit into
sysprog21:mainfrom
open-sources-port:getpriority-PRIO_PROCESS

Conversation

@doanbaotrung

@doanbaotrung doanbaotrung commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Linux treats thread IDs as valid PRIO_PROCESS targets because each thread is a task. elfuse only accepted who 0 and the guest process ID, so getpriority(PRIO_PROCESS, tid) returned ESRCH for live guest threads.

Share PRIO_PROCESS target validation between getpriority and setpriority, accepting live guest TIDs from the thread table.

Add regression coverage for live thread getpriority, live thread setpriority, and dead thread ESRCH behavior.

Fix #231


Summary by cubic

Accept live guest TIDs as PRIO_PROCESS targets in getpriority, matching Linux and avoiding ESRCH for running threads. Add a shared proc_pid_alive used by getpriority and sched_* queries; keep setpriority self-only while nice is process-wide; add tests for live TID get, non-self set ESRCH, and dead TID ESRCH. Fixes #231.

Written for commit 41fa2d2. Summary will update on new commits.

Review in cubic

cubic-dev-ai[bot]

This comment was marked as resolved.

@doanbaotrung
doanbaotrung force-pushed the getpriority-PRIO_PROCESS branch from e2836c0 to 4e48ed6 Compare July 20, 2026 06:35
@jserv
jserv requested a review from Max042004 July 20, 2026 23:56
Comment thread src/syscall/proc-identity.c Outdated
Comment thread src/syscall/proc-identity.c Outdated
Comment thread tests/test-credentials.c Outdated
Comment thread tests/test-credentials.c Outdated
Comment thread tests/test-credentials.c Outdated
@doanbaotrung
doanbaotrung force-pushed the getpriority-PRIO_PROCESS branch from 4e48ed6 to 28bb50b Compare July 21, 2026 01:37
Linux treats thread IDs as valid PRIO_PROCESS targets because each
thread is a task. elfuse only accepted who 0 and the guest process ID,
so getpriority(PRIO_PROCESS, tid) returned ESRCH for live guest
threads.

Add a shared process/TID liveness helper and use it from both scheduler
queries and getpriority.

Keep setpriority self-only while elfuse stores nice as one process-wide
value. This avoids silently accepting a live TID and mutating the nice
value reported for every task.

Add regression coverage for live thread getpriority, non-self
setpriority rejection, and dead thread ESRCH behavior.

Fix sysprog21#231
@doanbaotrung
doanbaotrung force-pushed the getpriority-PRIO_PROCESS branch from 28bb50b to 41fa2d2 Compare July 21, 2026 01:38
@doanbaotrung

Copy link
Copy Markdown
Collaborator Author

Fixed the review comments.

Changed:

  • Hoisted the shared PID/TID liveness helper to proc_pid_alive() in proc-identity.c.
  • Replaced the scheduler-local sched_pid_alive() in sys.c with proc_pid_alive().
  • Kept getpriority(PRIO_PROCESS, live_tid) supported.
  • Changed setpriority(PRIO_PROCESS, live_tid, ...) to return -ESRCH for non-self TIDs, since emu_nice is still process-global.
  • Updated the comment in proc.h to document that model.
  • Fixed the tests:
    • removed pointless CLONE_SETTLS
    • used named clone flags
    • made dead-TID test top-level
    • changed fixed retry count to a 2s monotonic time bound
    • updated setpriority coverage to assert rejection and no global nice mutation

@jserv
jserv merged commit 8ebede7 into sysprog21:main Jul 21, 2026
10 checks passed
@jserv

jserv commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Thank @doanbaotrung for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getpriority(PRIO_PROCESS, tid) returns ESRCH for live guest threads

2 participants